<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <!--Import Google Icon Font-->
    <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <!--Import materialize.css-->
    <link type="text/css" rel="stylesheet" href="css/materialize.min.css"  media="screen,projection"/>
    <!--Let browser know website is optimized for mobile-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1">-->
    <title>设置</title>

  
    <!--Import jQuery before materialize.js-->
      <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
      <script type="text/javascript" src="js/materialize.min.js"></script>
    <style type="text/css">       
        body {
            background: #ddffcc;
        }
        
        .panel {
            margin: auto;
            margin-top: 100px;
            padding: 10%;
            padding-top: 2%;
            width: 520px;
            height: 500px;
            background-color: #fff;
            border-radius: 20px;
            box-shadow: 0px 0px 20px #60aa70;
        }
        
        #logo {
            margin-top: 30px;
            margin-bottom: 40px;
            text-align: center
        }
        
        #submit {
            width: 100px;
            margin: auto;
            margin-top: 50px;
        }

    </style>

</head>
<script>
    $(document).ready(
        function() {
        $("#submit").click(
        function() {                      //jQuery中的id选择器
            var name = $("#username").val();                  //name
            var old_pwd = $("#old_password").val();
            var new_pwd = $("#new_password").val();
            //alert(name + "," + pwd);
            if (!checkInput("旧密码" , old_pwd) || !checkInput("姓名" , name)||!checkInput("新密码" , new_pwd)) {
                return
            }
            
            var settings = {
                type: "POST",
                url: "../../Fanxiangle/servlet/manager",             //
                dataType: "json",
                data: {
                    module: "admin",                //
                    action: "password",                //
                    username: name,
                    old_password:old_pwd
                    new_password: new_pwd

                },
                error: function(XHR, textStatus, errorThrown) {
                    alert("网络错误");
                },
                success: function(data, textStatus) {
                    if (textStatus == "success") {
                        if (data.status == true) {
                            //alert("操作成功")
                            var aid = getCookie('aid')                  ////
                            if (!aid || aid != data.data.aid) {
                                setCookie('aid', data.data.aid, 1)
                            }
                            var username = getCookie('username')
                            if (!username || username != data.data.username) {
                                setCookie('username', data.data.username, 1)
                            }
                            var sessionid = getCookie('sessionid');                  ////
                            if(!sessionid || sessionid != data.data.sessionid) {
                                setCookie('sessionid',data.data.sessionid,1)
                            }
                            //tiaozhuan
                       
                        } else if (data.errorCode == 101) {
                            alert("原密码错误")
                        } else if (data.errorCode == 102) {
                            alert("数据库错误")
                        } else if (data.errorCode == 103) {
                            alert("未知错误")
                        }
                        //alert("data:" + data.data.aid + ",status:" + textStatus)
                    }

                },
            };
            $.ajax(settings);
        });
    });


</script>

<body class="light-green lighten-4">

    <nav class="myNav">
      <div class="nav-wrapper   light-green darken-4">
        <a href="" class="brand-logo">&nbsp武侯祠管理系统</a>
        <ul id="nav-mobile" class="right hide-on-med-and-down">
          <li><a href="">景点</a></li>
          <li><a href="">美食</a></li>
          <li><a href="">厕所</a></li>
          <li><a href="">新闻</a></li>
          <li><a href="">广播</a></li>
          <li><a href="">反馈</a></li>
          <li><a href="">设置</a></li>
        </ul>
      </div>
    </nav>

    <div class="container ">
        <div class="panel ">
            <h4 id="logo">设置<small>-修改密码</small></h4>
            <form>
                <input type="hidden" name="module" value="admin">
                <input type="hidden" name="action" value="login">
                <div class="form-group">
                    <label for="username">用户名</label>
                    <input type="text" class="form-control" id="username" name="username" placeholder="用户名">
                </div>
                <div class="form-group">
                    <label for="old_password">旧密码</label>
                    <input type="text" class="form-control" id="old_password" name="old_password" placeholder="旧密码">
                </div>
                  <div class="form-group">
                    <label for="new_password">新密码</label>
                    <input type="text" class="form-control" id="new_password" name="new_password" placeholder="新密码">
                </div>
                <button type="button" class="btn btn-primary btn-block light-green" id="submit">修改</button>
            </form>

        </div>
    </div>

</body>

</html>

